package com.cg.big_event.service.impl;
import com.cg.big_event.entity.Category;
import com.cg.big_event.mapper.CategoryMapper;
import com.cg.big_event.service.CategoryService;
import com.cg.big_event.utils.ThreadLocalUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {
    @Resource
    private CategoryMapper categoryMapper;
    @Override
    public void add(Category category) {
        category.setCreateTime (LocalDateTime.now());
        category.setUpdateTime (LocalDateTime.now());
       Map<String ,Object> map= ThreadLocalUtil.get ();
        String idStr = (String) map.get("id");
        Integer id = Integer.parseInt(idStr);
        category.setCreateUser(String.valueOf(id));
        categoryMapper.add(category);
    }

    @Override
    public List<Category> list() {
        Map<String,Object> map= ThreadLocalUtil.get ();
        String idStr = (String) map.get("id");
        Integer id = Integer.parseInt(idStr);
        return categoryMapper.list(id);
    }

    @Override
    public Category detail(Integer id) {
        return categoryMapper.detail(id);
    }

    @Override
    public void update(Category category) {
        categoryMapper.update(category);
    }

    @Override
    public void delete(Integer id){
    categoryMapper.delete(id);
}
}
